home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / BUS / TMCM Software and Labs.sit / Software for TMCM 7_95 / Files for Lab 11 / Trees < prev   
Text File  |  1993-10-31  |  1KB  |  60 lines

  1.  
  2. SUB Tree(size, complexity)
  3.  
  4.  { This subroutine (from Figure 7.8 of "The Most
  5.    Complex Machine") draws a recursive tree.  Its
  6.    height is given, approximately, by the parameter
  7.    size; the number of levels of branching is given
  8.    by the parameter complexity.  The tree has its
  9.    "root" at the current turtle position; after the
  10.    tree is drawn, the turtle is left at its original
  11.    position and heading. }
  12.  
  13.    IF complexity = 0 THEN
  14.       forward(size)
  15.       back(size)
  16.    ELSE 
  17.       forward(size/2)
  18.       turn(45)
  19.       Tree(size/2, complexity - 1)
  20.       turn(-90)
  21.       Tree(size/2, complexity - 1)
  22.       turn(45)
  23.       back(size/2)
  24.    END IF
  25.  
  26. END SUB
  27.  
  28.  
  29. SUB TestTree
  30.  
  31.  { This subroutine can be called to draw sample trees;
  32.    the user is asked to specify the complexity and a
  33.    tree of that complexity is drawn filling most of the
  34.    screen. }
  35.  
  36.    DECLARE complexity
  37.  
  38.    penUp
  39.    MoveTo(0,-9)
  40.    penDown
  41.    face(90)
  42.    clear
  43.  
  44.    AskUser("What level of complexity do you want (0 to 12)?", complexity)
  45.  
  46.    complexity := trunc(complexity)  { Make sure value is OK }
  47.    IF complexity < 0 THEN
  48.       complexity := 0
  49.       TellUser("Using complexity = 0.")
  50.    END IF
  51.    IF complexity > 12 THEN
  52.       complexity := 12
  53.       TellUser("Using complexity = 12.")
  54.    END IF
  55.  
  56.    Tree(18,complexity)
  57.  
  58. END SUB
  59.  
  60.